package com.qbkj.base_lib.adapter;

import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.qbkj.base_lib.listener.OnConvertListener;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by St on 2018/4/10.
 */

public abstract class QuickAdapter<T, K extends BaseViewHolder> extends BaseQuickAdapter<T, K> {

    private OnConvertListener mOnConvertListener;
    private LoadingAdapterValue mLoadingAdapterValue;

    public QuickAdapter(@LayoutRes int layoutResId, @Nullable List data) {
        super(layoutResId, data);
        mLoadingAdapterValue = new LoadingAdapterValue<T>(data);

    }

    @Override
    public K onCreateViewHolder(ViewGroup parent, int viewType) {
        K baseViewHolder = super.onCreateViewHolder(parent, viewType);
        AutoUtils.auto(baseViewHolder.itemView);
        return baseViewHolder;
    }

    @Override
    protected void convert(K helper, T item) {
        int position = helper.getAdapterPosition();
        if (mOnConvertListener != null) mOnConvertListener.convert(helper, item);
        //tag赋值
        mLoadingAdapterValue.setValue(helper.itemView, position, item);

    }

    public void setOnConvertListener(OnConvertListener mOnConvertListener) {
        this.mOnConvertListener = mOnConvertListener;
    }


    //设置网络图片头
    public void setImageHeadUrl(String mImageHeadUrl) {
        mLoadingAdapterValue.setImageHeadUrl(mImageHeadUrl);
    }


}
